 var map = null;
var vm = new Vue({
    el : "#sxkSjList",
    data : {
        alls : [],
        grid: null
    },
    init:function(){
        var _self = this;

    },

    methods: {

        getEqByCode:function(event){
            var _self = this;
            var eqCode = document.getElementById("eqCode").value;   //设备编码

            if (event && (event.keyCode != 13 || !(eqCode && eqCode.length > 0))) {
                return;
            }

            var data ={
                eqCode : eqCode
            };

            this.$nextTick(function() {
                this.$http.post("../../sxkXjList/selectAllEqList",data,{emulateJSON: true}).then(function(res){
                    if(res.ok){
                        _self.tableList = res.body.AllLists;

                    }
                    layui.use(['form'], function(){
                        var form = layui.form;
                        _self.$options.methods.renderTable(_self,_self.tableList);

                    });
                });
            });
        },
        saveProductionData:function(event){
            var _self = this;

            var eqCodes = document.getElementById("eqCode").value;   //设备编码
            if (eqCodes== null || eqCodes== "") {
                layer.msg("目标机台不能为空!");
                return;
            }
            var xxLists = _self.table.cache.sxkXjListTable;

            var wlIds ="";
            var ysIds ="";
            var dwIds ="";
            var xjqtys = "";
            var kcqtys = "";
            var aa = xxLists[0].OUTQTYS;
            for (var i = 0;i < xxLists.length;i ++) {

                if(xxLists[i].OUTQTYS != null){
                    //正则表达式验证下架数量是否为数字
                    var reg = "([1-9][0-9]*(\\.\\d{1,2})?)|(0\\.\\d{1,3})";
                    var pattern=new RegExp(reg);

                    if (!pattern.test((xxLists[i].OUTQTYS))) {
                        layer.msg(xxLists[i].WLNAME+"请输入正确的下架数量！")
                        return false;
                    }
                   //判断录入的下架数量是否超过当前库存数量
                    if(xxLists[i].OUTQTYS > xxLists[i].QTYS){
                        layer.msg(xxLists[i].WLNAME+"下架数量超过库存数量！")
                        return false;
                    }
                    wlIds += wlIds + xxLists[i].WLID+",";;
                    ysIds += ysIds + xxLists[i].YSID+",";;
                    dwIds += dwIds + xxLists[i].DWID+",";;
                    xjqtys += xjqtys +xxLists[i].OUTQTYS+",";;
                }
            }


            var data ={
                eqCodes : eqCodes ,
                wlIds : wlIds ,
                ysIds : ysIds ,
                dwIds : dwIds ,
                xjqtys : xjqtys
            };

            this.$nextTick(function() {
                this.$http.post("../../sxkXjList/saveCkXiajiaLists",data,{emulateJSON: true}).then(function(res){
                    if(res.ok){
                        _self.result = res.body.results;

                        if(_self.result == "false"){
                            layer.msg("处理失败");
                        }else{
                            layer.msg("处理成功");
                            window.setTimeout(function() {
                                window.location.reload();
                            }, 1000);
                        }
                    }else{
                        layer.msg("下架失败");
                    }
                });
            });
        },
        reset:function(data){
            window.location.reload();
        },
        vueAlert:function(msg){
            layui.use(['form'], function(){
                var layer = layui.layer;
                layer.msg(msg,{icon:6,time:2000});
            });
        },
        renderTable: function(_self,data){


            layui.use(['form','table','laydate'], function(){
                _self.table = layui.table;
                var form = layui.form;

                _self.grid = _self.table.render({
                    elem: '#sxkXjListTable',
                    width: 'full-20',
                    height: 'full-150',
                    cols: [[ //标题栏
                        { field: 'WLNAME', title: '物料名称',width: 200},
                        {field: 'YSNAME', title: '颜色',width: 200, align:'center' },
                        {field: 'QTYS', title: '库存数量', minWidth: 200,align:'center'},
                        {field: 'OUTQTYS', title: '下架数量', minWidth: 200,align:'center',edit: 'text'},
                        {field: 'DWNAME', title: '单位', minWidth: 200,align:'center'}
                    ]],
                    data: data,
                    page: true, //是否显示分页
                    limits: [10, 20, 50],
                    limit: 15 ,//每页默认显示的数量
                });
                // 监听行工具事件
                _self.table.on('edit(remakeReceiveFilter)', function(obj) {
                    obj.update(obj.data);// 修改当前行数据
                });
            });
        }
    }
});